package com.sddfp.trade.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import com.sddfp.common.pojo.BorrowRecordDTO;
import com.sddfp.common.pojo.BorrowRecordQuery;
import com.sddfp.common.pojo.BorrowRecordVo;
import com.sddfp.common.pojo.Pages;
import com.sddfp.common.result.Result;
import com.sddfp.trade.entity.AgencyBidDTO;
import com.sddfp.trade.entity.AgencyBidVo;
import com.sddfp.trade.entity.BorrowRecord;
import com.sddfp.trade.service.IAgencyBidService;
import com.sddfp.trade.service.IBorrowRecordService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yellow Docter
 * @date 2023 -07-31
 * @desc
 */
@RestController
public class TradeController {

    @Autowired
    private IBorrowRecordService borrowRecordService;

    @Autowired
    private IAgencyBidService agencyBidService;


    @ApiOperation("机构认购")
    @PostMapping("/trade/agency/bid/add")
    public Result<AgencyBidVo> addAgencyBid(
            @RequestBody AgencyBidDTO agencyBidDTO) {
        AgencyBidVo tenderDTO=agencyBidService.addAgencyBidRecord(agencyBidDTO);
        return Result.ok(tenderDTO);
    }


    @ApiOperation("借款申请")
    @PostMapping("/trade/borrow/add")
    public Result addBorrowRecord(@RequestBody BorrowRecordDTO borrowRecordDTO) {
        borrowRecordService.addBorrowRecord(borrowRecordDTO);
        return Result.ok();
    }

    @ApiOperation("借款记录查询")
    @PostMapping("/trade/borrow/query")
    public Result<Pages<BorrowRecordVo>> queryBorrowRecord(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "2") Integer pageSize,
            @RequestBody BorrowRecordQuery borrowRecordQuery) {
        Pages<BorrowRecordVo> pages =
                borrowRecordService.queryBorrowRecord(pageNum,pageSize,borrowRecordQuery);
        return Result.ok(pages);
    }

//    @ApiOperation("查询借款记录")
//    @GetMapping("/auth/trade/search")
//    public Result searchborrowRecord(String name, String createDate) {
//
//        LambdaQueryWrapper<BorrowRecord> borrowRecordLambdaQueryWrapper = Wrappers.lambdaQuery(BorrowRecord.class);
//
//        if (StringUtils.isNotBlank(name)) {
//            borrowRecordLambdaQueryWrapper.like(BorrowRecord::getName, name);
//        }
//        if (StringUtils.isNotBlank(createDate)) {
//            borrowRecordLambdaQueryWrapper.gt(BorrowRecord::getCreateDate, createDate);
//        }
//
//        List<BorrowRecord> list = borrowRecordService.list(borrowRecordLambdaQueryWrapper);
//
//        return Result.ok(list);
//    }

    @ApiOperation("借款审核接口,同步借款数据")
    @PutMapping("/trade/borrow/status")
    public Result verifyStatus(Integer approveStatus,Long borrowRecordId){
        String result = borrowRecordService.verifyStatus(approveStatus,borrowRecordId);
        return Result.ok(result);
    }


//    @ApiOperation("借款记录审核")
//    @GetMapping("/auth/trade/status/{borrowId}/{status}")
//    public String tradeChangeStatus(
//            @PathVariable("borrowId") Long borrowId,
//            @PathVariable("status") Integer status) {
//        String result = borrowRecordService.changeStatus(borrowId, status);
//        return result;
//    }

//    @ApiOperation("机构认购投资理财产品")
//    @PostMapping("/auth/trade/agency/bid/add/{borrowId}/{amount}")
//    public Result addAgencyBid(
//            @PathVariable("borrowId") Long borrowId,       //借款的id
//            @PathVariable("amount") Integer amount) {      //投机的金额
//
//        //投资认证流程
//        Map<String, Object> map = borrowRecordService.addAgencyBid(borrowId, amount);
//        return  Result.ok(map);
//    }

//    @ApiOperation("机构认购投资的审核")
//    @PostMapping("/trade/agency/bid/status")
//    public String agencyBidStatus(
//            @RequestParam("borrowId")Long borrowId,         //借款id
//            @RequestParam("commission")String commission,   //平台佣金
//            @RequestParam("status")String status            //审核状态
//    ){
//
//       String result =  borrowRecordService.agencyBidStatus(borrowId,commission,status);
//       return result;
//
//    }





}
